<template>
  <div>
    <!-- 头部标签 -->
    <van-nav-bar fixed>
      <template #left>
        <!-- <img class="logo" src="../../assets/toutiao_logo.png" alt="" /> -->
        <img class="logo" :src="imgObj"/>
      </template>
      <template #right>
        <van-icon name="search" size="0.48rem" color="#fff"/>
      </template>
    </van-nav-bar>
    <!-- 频道部分 -->
    <van-tabs v-model="channelId" animated sticky offset-top="1.226667rem">
      <!-- <van-tab title="标签 1">内容 1</van-tab>
      <van-tab title="标签 2">内容 2</van-tab>
      <van-tab title="标签 3">内容 3</van-tab>
      <van-tab title="标签 4">瞎搞</van-tab> -->
      <van-tab v-for="item in userChannelList" :title="item.name" :key="item.id" :name="item.id">
        <ArticleList :arr="articleList"/>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import { getUserChannelListAPI, getArticleListAPI } from '@/api/home'
import logoPng from '@/assets/images/logo.png'
import ArticleList from './articleList.vue'
// import { getArticleListAPI } from '@/api/home.js'
export default {
  name: 'Home',
  data () {
    return {
      imgObj: logoPng,
      userChannelList: [], // 用户选择的列表
      channelId: 0, // 默认值是0 表示推荐频道
      articleList: [] // 当前显示的列表
    }
  },
  async created () {
    let res = await getUserChannelListAPI()
    this.userChannelList = res.data.data.channels
    res = await getArticleListAPI(this.channelId)
    this.articleList = res.data.data.results
    console.log(this.articleList)
  },
  components: {
    ArticleList
  }
}
</script>

<style scoped lang="less">
.logo {
  width: 100px;
  height: 30px;
}
/* tab内容距离tab导航的距离 */
/deep/ .van-tabs__content{
  padding-top: 44px;
}
</style>
